iT邦幫忙

2023 iThome 鐵人賽

DAY 6
0
Modern Web

Micro-Frontend 的新夥伴:Astro.js 的應用與研究系列 第 6

[Day 06] Client Directives - 設定 JS 不同的生效類型

  • 分享至 

  • xImage
  •  

在昨天的 Vue 範例中 , 我們使用了 <Counter client:idle/> 如果眼尖的邦友一定有注意到

我們在引用 Counter 元件時多加一個 client:idle 這個屬性

其實 , Astro 為了達到高分的 Web vital 預設是會將

Client Directives
Section titled Client Directives
These directives control how UI Framework components are hydrated on the page.

By default, a UI Framework component is not hydrated in the client. If no client:* directive is provided, its HTML is rendered onto the page without JavaScript.

A client directive can only be used on a UI framework component that is directly imported into a .astro component. Hydration directives are not supported when using dynamic tags and custom components passed via the components prop.

client:load
Section titled client:load
Priority: High
Useful for: Immediately-visible UI elements that need to be interactive as soon as possible.
Load and hydrate the component JavaScript immediately on page load.

client:idle
Section titled client:idle
Priority: Medium
Useful for: Lower-priority UI elements that don’t need to be immediately interactive.
Load and hydrate the component JavaScript once the page is done with its initial load and the requestIdleCallback event has fired. If you are in a browser that doesn’t support requestIdleCallback, then the document load event is used.

client:visible
Section titled client:visible
Priority: Low
Useful for: Low-priority UI elements that are either far down the page (“below the fold”) or so resource-intensive to load that you would prefer not to load them at all if the user never saw the element.
Load and hydrate the component JavaScript once the component has entered the user’s viewport. This uses an IntersectionObserver internally to keep track of visibility.

client:only

參考資料


上一篇
[Day 05] 接入 Vue . React 的元件 - Integrations
下一篇
[Day 07] Nanostore - 跨越 Island 的資料管理
系列文
Micro-Frontend 的新夥伴:Astro.js 的應用與研究20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言